load("@io_bazel_rules_go//go:def.bzl", "go_embed_data", "go_library", "go_test")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

go_test(
    name = "go_default_test",
    srcs = ["embed_test.go"],
    data = [
        "BUILD.bazel",
        "//:AUTHORS",
        "@com_google_protobuf//:LICENSE",
    ],
    embed = [":go_default_library"],
    deps = ["//go/tools/bazel:go_default_library"],
)

go_library(
    name = "go_default_library",
    srcs = [
        ":cgo",
        ":empty",
        ":ext",
        ":flat",
        ":local",
        ":single",
        ":str",
        ":unpack",
    ],
    importpath = "github.com/bazelbuild/rules_go/tests/go_embed_data",
)

go_embed_data(
    name = "cgo",
    srcs = ["error.c"],
    package = "go_embed_data",
    var = "cgo",
)

go_embed_data(
    name = "empty",
    package = "go_embed_data",
    var = "empty",
)

go_embed_data(
    name = "single",
    src = "//:AUTHORS",
    package = "go_embed_data",
    var = "single",
)

go_embed_data(
    name = "local",
    srcs = [
        ":BUILD.bazel",
        "@io_bazel_rules_go//:AUTHORS",
    ],
    package = "go_embed_data",
    var = "local",
)

go_embed_data(
    name = "ext",
    srcs = ["@com_google_protobuf//:LICENSE"],
    package = "go_embed_data",
    var = "ext",
)

go_embed_data(
    name = "flat",
    srcs = [":BUILD.bazel"],
    flatten = True,
    package = "go_embed_data",
    var = "flat",
)

go_embed_data(
    name = "str",
    srcs = [":BUILD.bazel"],
    package = "go_embed_data",
    string = True,
    var = "str",
)

go_embed_data(
    name = "unpack",
    srcs = [
        ":embedded_tar",
        ":embedded_zip",
    ],
    package = "go_embed_data",
    unpack = True,
    var = "unpack",
)

pkg_tar(
    name = "embedded_tar",
    srcs = [":BUILD.bazel"],
    package_dir = "/from-tar",
)

genrule(
    name = "embedded_zip",
    srcs = [":BUILD.bazel"],
    outs = ["embedded_zip.zip"],
    cmd = "$(location @bazel_tools//tools/zip:zipper) c $@ from-zip/BUILD.bazel=$(location :BUILD.bazel)",
    tools = ["@bazel_tools//tools/zip:zipper"],
)
